package com.example.clxy.service.impl;

import com.example.clxy.dao.InnovationMapper;
import com.example.clxy.dao.InnovationStudentGxMapper;
import com.example.clxy.dao.UserMapper;
import com.example.clxy.entity.*;
import com.example.clxy.entity.dto.InnovationApplyDto;
import com.example.clxy.result.PageResult;
import com.example.clxy.result.WebRestResult;
import com.example.clxy.result.business.InnovationRemindResult;
import com.example.clxy.result.business.InnovationResult;
import com.example.clxy.result.business.PageResult.InnovationAdminPageResult;
import com.example.clxy.result.business.PageResult.InnovationStudentPageResult;
import com.example.clxy.result.business.PageResult.InnovationUserFilePageResult;
import com.example.clxy.result.business.StudentInnovationResult;
import com.example.clxy.service.InnovationService;
import com.example.clxy.util.FileUtil;
import com.example.clxy.util.Tools;
import com.example.clxy.util.UUIDUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.List;

/**
 * @Author liuhaoqi
 * @Date 2020/8/10 15:17
 * @Version 1.0
 */
@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class InnovationServiceImpl implements InnovationService {

    @Autowired
    InnovationMapper innovationMapper;
    @Autowired
    UserMapper userMapper;
    @Autowired
    FileServiceImpl fileServiceImpl;
    @Autowired
    InnovationStudentGxMapper innovationStudentGxMapper;


    @Override
    public WebRestResult addInnovation(InnovationApplyDto innovationApplyDto) {
        WebRestResult result = new WebRestResult();
        if (innovationApplyDto == null || innovationApplyDto.getTeacherid() == null || innovationApplyDto.getTeacherid().equals("")) {
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("老师id为空不允许新增数据！");
            return result;
        }
        Innovation innovation = new Innovation();
        BeanUtils.copyProperties(innovationApplyDto, innovation);
        innovation.setInnovationid(UUIDUtil.randomUUID());
        innovation.setFlag("0");
        innovation.setCreatedTime(new Date());
        innovation.setUpdatedTime(new Date());
        //0默认未发起申请的创新实验
        innovation.setApplystatus("0");
        // 0 未完成
        innovation.setFinishstatus("0");
        if (innovationMapper.insert(innovation) == 1 &&
                innovationMapper.insertInnovationTeacher(innovation.getInnovationid(), innovationApplyDto.getTeacherid()) == 1) {
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("老师新增创新实验成功！！");
            return result;
        } else {
            result.setResult(WebRestResult.FAILURE);
            result.setMessage("老师新增创新实验失败！");
            return result;
        }
    }

    @Override
    public WebRestResult updateInnovation(InnovationApplyDto innovationApplyDto) {
        WebRestResult result = new WebRestResult();
        Innovation innovation = new Innovation();
        BeanUtils.copyProperties(innovationApplyDto, innovation);

        innovation.setUpdatedTime(new Date());
        if (innovationMapper.updateByPrimaryKeySelective(innovation) == 1) {
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("更新创新实验成功！");
            return result;
        } else {
            result.setResult(WebRestResult.FAILURE);
            result.setMessage("更新创新实验失败！");
            return result;
        }
    }

    @Override
    public WebRestResult deleteInnovation(String innovationid) {
        WebRestResult result = new WebRestResult();
        if (innovationMapper.deleteInnovation(innovationid) == 1 && innovationMapper.deleteInnovationTeacher(innovationid) == 1) {
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("删除创新实验成功！");
        } else {
            result.setResult(WebRestResult.FAILURE);
            result.setMessage("删除创新实验失败！");
        }
        return result;
    }

    @Override
    public WebRestResult withdrawInnovation(String innovationid) {
        WebRestResult result = new WebRestResult();
        if (innovationMapper.withdrawInnovation(innovationid) == 1) {
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("老师撤回创新实验申请成功！");
            return result;
        } else {
            result.setResult(WebRestResult.FAILURE);
            result.setMessage("老师撤回创新实验申请失败！");
            return result;
        }
    }

    @Override
    public WebRestResult approveInnovation(String innovationid, String applystatus, String rejectreason) {
        WebRestResult result = new WebRestResult();
        Date publishdate = null;
        if ("1002".equals(applystatus)) {
            publishdate = new Date();
            if (innovationMapper.approveInnovation(innovationid, applystatus, rejectreason, publishdate) == 1) {
                result.setResult(WebRestResult.SUCCESS);
                result.setMessage("管理员审批通过了该创新实验");
                return result;
            }
        }
        if ("1003".equals(applystatus)) {
            if (innovationMapper.approveInnovation(innovationid, applystatus, rejectreason, publishdate) == 1) {
                result.setResult(WebRestResult.SUCCESS);
                result.setMessage("管理员审批拒绝了该创新实验");
                return result;
            }
        }

        return result;
    }

    @Override
    public WebRestResult applyInnovationStudent(String innovationid, String studentid, String applyreason, MultipartFile file) {
        WebRestResult result = new WebRestResult();
//        InnovationStudentGx innovationStudentGx = new InnovationStudentGx();
//        try {
//            if (file != null) {
//                WebRestResult validateResult = null;
//                validateResult = FileUtil.validateFile(file,studentid);
//                if (validateResult.getResult() == WebRestResult.FAILURE) {
//                    //文件校验失败 抛异常
//                    result.setMessage(validateResult.getMessage());
//                    throw new Exception(validateResult.getMessage());
//                }
//                String stupath = userMapper.getStuPath(studentid);
//                Innovation innovation = innovationMapper.selectByPrimaryKey(innovationid);
//                String filepath= "innovation\\"+innovation.getInnovationname()+"\\"+stupath;
//                filepath = FileUtil.getAbsolutePath(filepath);
//                String filename = "jianli" + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
//                WebRestResult upload = fileServiceImpl.upload(file, filepath, filename);
//                if (upload.getResult() == WebRestResult.FAILURE) {
//                    result.setMessage(upload.getMessage());
//                    //文件上传失败，抛异常
//                    throw new Exception(upload.getMessage());
//                }
//                innovationStudentGx.setApplyfilepath((filepath + filename).replace("\\", "/"));
//            }
//        }catch (Exception e) {
//            result.setResult(WebRestResult.FAILURE);
//            e.printStackTrace();
//            //捕获异常 手动回滚事务
//            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//            return result;
//        }
//        innovationStudentGx.setStudentid(studentid);
//        innovationStudentGx.setInnovationid(innovationid);
//        innovationStudentGx.setApplyreason(applyreason);
//        innovationStudentGx.setApplystatus("0");
//        innovationStudentGx.setFlag("0");
//        innovationStudentGx.setCreatedTime(new Date());
//        innovationStudentGx.setUpdatedTime(new Date());
//        if (innovationStudentGxMapper.insertSelective(innovationStudentGx) == 1) {
//            result.setResult(WebRestResult.SUCCESS);
//            result.setMessage("学生申请创新实验成功！");
//            return result;
//        }
        return result;
    }

    @Override
    public WebRestResult withdrawInnovationStudent(String innovationid, String studentid, String withdrawreason) {
        WebRestResult result = new WebRestResult();
        if (innovationMapper.withdrawInnovationStudent(innovationid, studentid, withdrawreason) == 1) {
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("学生撤回创新实验申请成功！");
            return result;
        } else {
            result.setResult(WebRestResult.FAILURE);
            result.setMessage("学生撤回创新实验申请失败！");
            return result;
        }
    }

    @Override
    public WebRestResult uploadProjectFile(MultipartFile file, String innovationid, String userid) {
        if (FileUtil.validateFile(file, userid).getResult() == WebRestResult.FAILURE) {
            return FileUtil.validateFile(file, userid);
        }
        WebRestResult result = new WebRestResult();
        String stupath = "";
        User user = userMapper.selectByPrimaryKey(userid);
        if (user.getRoleid().equals("3")) {
            stupath = userMapper.getStuPath(userid);
        } else {
            stupath = user.getUsername()+"\\";
        }
        Innovation innovation = innovationMapper.selectByPrimaryKey(innovationid);
        String filepath = "innovation\\" + innovation.getInnovationname() + "\\" + stupath;
        String absolutePath = FileUtil.getAbsolutePath(filepath);
        String filename = UUIDUtil.randomUUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
        WebRestResult upload = fileServiceImpl.upload(file, absolutePath, filename);
        if (upload.getResult() == WebRestResult.FAILURE) {
            return upload;
        }
        String newFileName = (filepath + filename).replace("\\", "/");
        String projectfile = FileUtil.FilePathUrl + newFileName;
        String originalFilename = file.getOriginalFilename();

        if (innovationStudentGxMapper.uploadProjectfileByStudent(innovationid, userid, projectfile,originalFilename) == 1) {
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("学生上传创新项目文件成功！ 该项目路径为" + projectfile);
        }
        return result;
    }

    @Override
    public WebRestResult uploadApplyFile(MultipartFile file, String studentid, String innovationid) {
        if (FileUtil.validateFile(file, studentid).getResult() == WebRestResult.FAILURE) {
            return FileUtil.validateFile(file, studentid);
        }
        WebRestResult result = new WebRestResult();
        String stupath = userMapper.getStuPath(studentid);
        Innovation innovation = innovationMapper.selectByPrimaryKey(innovationid);
        String filepath = "innovation\\" + innovation.getInnovationname() + "\\" + stupath;
        String absolutePath = FileUtil.getAbsolutePath(filepath);
        System.out.println(absolutePath);
        String filename = "jianli" + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
        WebRestResult upload = fileServiceImpl.upload(file, absolutePath, filename);
        if (upload.getResult() == WebRestResult.FAILURE) {
            return upload;
        }
        String newFileName = (filepath + filename).replace("\\", "/");
        result.setResult(WebRestResult.SUCCESS);
        System.out.println(FileUtil.FilePathUrl);
        result.setMessage(FileUtil.FilePathUrl + newFileName);
        return result;
    }

    @Override
    public WebRestResult addInnovationStudent(@RequestBody InnovationStudentGx innovationStudent) {
        WebRestResult result = new WebRestResult();
        innovationStudent.setCreatedTime(new Date());
        innovationStudent.setUpdatedTime(new Date());
        innovationStudent.setApplystatus("1001");
        innovationStudent.setFlag("0");
        if (innovationStudentGxMapper.insertSelective(innovationStudent) == 1) {
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("学生申请创新实验成功！");
            return result;
        } else {
            result.setResult(WebRestResult.FAILURE);
            result.setMessage("学生申请创新实验失败！");
            return result;
        }
    }

    @Override
    public WebRestResult updateInnovationStudent(InnovationStudentGx innovationStudent) {
        WebRestResult result = new WebRestResult();
        innovationStudent.setUpdatedTime(new Date());
        if (innovationStudentGxMapper.updateByPrimaryKeySelective(innovationStudent) == 1) {
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("学生更新申请创新实验信息成功！");
            return result;
        } else {
            result.setResult(WebRestResult.FAILURE);
            result.setMessage("学生更新申请创新实验信息失败！");
            return result;
        }
    }

    @Override
    public WebRestResult approveInnovationByTeacher(String innovationid, String studentid, String applystatus, String rejectreason) {
        WebRestResult result = new WebRestResult();
        if ("1002".equals(applystatus)) {
            if (innovationStudentGxMapper.approveInnovationByTeacher(innovationid, studentid, applystatus, rejectreason) == 1) {
                result.setMessage("老师通过了学生申请创新实验");
                result.setResult(WebRestResult.SUCCESS);
                return result;
            } else {
                result.setResult(WebRestResult.FAILURE);
                result.setMessage("老师审核学生创新实验失败");
                return result;
            }
        } else if ("1003".equals(applystatus)) {
            if (innovationStudentGxMapper.approveInnovationByTeacher(innovationid, studentid, applystatus, rejectreason) == 1) {
                result.setMessage("老师拒绝了学生申请创新实验");
                result.setResult(WebRestResult.SUCCESS);
                return result;
            } else {
                result.setResult(WebRestResult.FAILURE);
                result.setMessage("老师审核学生创新实验失败");
                return result;
            }
        }
        return result;
    }


    @Override
    public StudentInnovationResult getInnovationByIdStudent(String innovationid, String studentid) {

        StudentInnovationResult studentInnovationResult = innovationMapper.getInnovationByIdStudent(innovationid, studentid);
        if (studentInnovationResult != null) {
            int  applynums = innovationStudentGxMapper.getApplyNumById(innovationid);
            int  curnums = innovationStudentGxMapper.getCurnumById(innovationid);
            studentInnovationResult.setApplynums(applynums);
            studentInnovationResult.setCurnums(curnums);
            studentInnovationResult.setResult(WebRestResult.SUCCESS);
            studentInnovationResult.setMessage("学生端根据创新实验id得到创新实验基本信息成功");
            return studentInnovationResult;
        } else {
            studentInnovationResult.setResult(WebRestResult.FAILURE);
            studentInnovationResult.setMessage("学生端根据创新实验id得到创新实验基本信息为空");
            return studentInnovationResult;
        }
    }

    @Override
    public PageResult<InnovationAdminPageResult> getInnovationListByAdmin(String innovationname,String applystatus, int page, int pagesize) {
        PageResult<InnovationAdminPageResult> result = new PageResult<>();
        int begin = (page - 1) * pagesize;
        int end = pagesize;

        List<InnovationAdminPageResult> innovationResultList = innovationMapper.getInnovationListByAdmin(innovationname,applystatus, begin, end, pagesize);
        if (innovationResultList.size() > 0) {

            for (InnovationAdminPageResult innovationAdminPageResult : innovationResultList) {
                int curnum = 0;
                int applynum = 0;
                List<StudentInnovationResult> innovationStudentList = innovationStudentGxMapper.getInnovationStudentListById(innovationAdminPageResult.getInnovationid());
                for (int i = 0; i < innovationStudentList.size(); i++) {
                    if ("1002".equals(innovationStudentList.get(i).getApplystatus())) {
                        curnum++;
                    }
                    if ("1001".equals(innovationStudentList.get(i).getApplystatus())||"1003".equals(innovationStudentList.get(i).getApplystatus())) {
                        applynum++;
                    }
                }
                applynum+=curnum;
                innovationAdminPageResult.setCurnums(curnum);
                innovationAdminPageResult.setApplynums(applynum);
                innovationAdminPageResult.setStudentInnovationResults(innovationStudentList);
            }
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("管理员获取创新实验列表成功！");
            result.setRows(innovationResultList);
            result.setTotal(innovationResultList.get(0).getCnt());
            result.setPageCount(innovationResultList.get(0).getPage());
            return result;
        } else {
            result.setResult(WebRestResult.FAILURE);
            result.setMessage("管理员获取创新实验列表为空！");
            return result;
        }
    }

    @Override
    public PageResult<InnovationAdminPageResult> getInnovationListByTeacher(String innovationname, String teacherid,String applystatus, int page, int pagesize) {
        PageResult<InnovationAdminPageResult> result = new PageResult<>();
        int begin = (page - 1) * pagesize;
        int end = pagesize;

        List<InnovationAdminPageResult> innovationResultList = innovationMapper.getInnovationListByTeacher(innovationname, teacherid, applystatus,begin, end, pagesize);
        if (innovationResultList.size() > 0) {
            for (InnovationAdminPageResult innovationAdminPageResult : innovationResultList) {
                int curnum = 0;
                int applynum = 0;
                List<StudentInnovationResult> innovationStudentList = innovationStudentGxMapper.getInnovationStudentListById(innovationAdminPageResult.getInnovationid());
                for (int i = 0; i < innovationStudentList.size(); i++) {
                    if ("1002".equals(innovationStudentList.get(i).getApplystatus())) {
                        curnum++;
                    }
                    if ("1001".equals(innovationStudentList.get(i).getApplystatus())||"1003".equals(innovationStudentList.get(i).getApplystatus())) {
                        applynum++;
                    }
                }
                applynum+=curnum;
                innovationAdminPageResult.setCurnums(curnum);
                innovationAdminPageResult.setApplynums(applynum);
                innovationAdminPageResult.setStudentInnovationResults(innovationStudentList);
            }
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("老师获取创新实验列表成功！");
            result.setRows(innovationResultList);
            result.setTotal(innovationResultList.get(0).getCnt());
            result.setPageCount(innovationResultList.get(0).getPage());
            return result;
        } else {
            result.setResult(WebRestResult.FAILURE);
            result.setMessage("老师获取创新实验列表为空！");
            return result;
        }
    }

    @Override
    public PageResult<InnovationAdminPageResult> getInnovationListByStudent(String innovationname, String studentid, String applystatus, int page, int pagesize) {
        PageResult<InnovationAdminPageResult> result = new PageResult<>();
        int begin = (page - 1) * pagesize;
        int end = pagesize;

        List<InnovationAdminPageResult> innovationResultList = innovationMapper.getInnovationListByStudent(innovationname, studentid, applystatus, begin, end, pagesize);
        if (innovationResultList.size() > 0) {
            for (InnovationAdminPageResult innovationAdminPageResult : innovationResultList) {
                int curnum = 0;
                int applynum = 0;
                List<StudentInnovationResult> innovationStudentList = innovationStudentGxMapper.getInnovationStudentListById(innovationAdminPageResult.getInnovationid());
                for (int i = 0; i < innovationStudentList.size(); i++) {
                    if ("1002".equals(innovationStudentList.get(i).getApplystatus())) {
                        curnum++;
                    }
                    if ("1001".equals(innovationStudentList.get(i).getApplystatus())||"1003".equals(innovationStudentList.get(i).getApplystatus())) {
                        applynum++;
                    }

                }
                applynum+=curnum;
                innovationAdminPageResult.setCurnums(curnum);
                innovationAdminPageResult.setApplynums(applynum);
                innovationAdminPageResult.setStudentInnovationResults(innovationStudentList);
            }
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("学生获取创新实验列表成功！");
            result.setRows(innovationResultList);
            result.setTotal(innovationResultList.get(0).getCnt());
            result.setPageCount(innovationResultList.get(0).getPage());
            return result;
        } else {
            result.setResult(WebRestResult.FAILURE);
            result.setMessage("学生获取创新实验列表为空！");
            return result;
        }
    }

    @Override
    public WebRestResult finishInnovationByTeacher(String teacherid, String innovationid) {
        WebRestResult result = new WebRestResult();

        if (innovationMapper.finishInnovationByTeacher(teacherid, innovationid) == 1) {
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("老师操作完成此创新实验成功！");
            return result;
        } else {
            result.setResult(WebRestResult.FAILURE);
            result.setMessage("老师操作完成此创新实验失败！");
            return result;
        }
    }

    @Override
    public WebRestResult applyInnovation(String innovationid) {
        WebRestResult result = new WebRestResult();
        Date date = new Date();
        String applydate= Tools.date2Str(date);
        if (innovationMapper.applyInnovation(innovationid,applydate) == 1) {
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("老师发起申请创新实验成功！");
            return result;
        } else {
            result.setResult(WebRestResult.FAILURE);
            result.setMessage("老师发起申请创新实验失败！");
            return result;
        }
    }

    @Override
    public PageResult<InnovationAdminPageResult> getInnovationListToApply(String innovationname, String studentid, int page, int pagesize) {
        PageResult<InnovationAdminPageResult> result = new PageResult<>();
        int begin = (page - 1) * pagesize;
        int end = pagesize;

        List<InnovationAdminPageResult> list = innovationMapper.getInnovationListToApply(innovationname, studentid, begin, end, pagesize);
        if (list.size() > 0) {
            result.setTotal(list.get(0).getCnt());
            result.setPageCount(list.get(0).getPage());
            result.setRows(list);
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("学生获取可申请的创新实验列表成功！");
            return result;
        } else {
            result.setResult(WebRestResult.FAILURE);
            result.setMessage("学生获取可申请的创新实验列表为空或失败！");
            return result;
        }
    }

    @Override
    public StudentInnovationResult getInnovationStudentInfobyId(String innovationid, String studentid) {
        StudentInnovationResult result = innovationStudentGxMapper.getInnovationStudentInfobyId(innovationid, studentid);
        if (result != null) {
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("根据创新实验id获取单个创新实验与学生关系信息成功");
            return result;
        } else {
            result.setResult(WebRestResult.FAILURE);
            result.setMessage("根据创新实验id获取单个创新实验与学生关系信息为空！");
            return result;
        }
    }

    @Override
    public InnovationResult getInnovationByIdTeacher(String innovationid, String teacherid) {
        InnovationResult result = innovationMapper.getInnovationByIdTeacher(innovationid, teacherid);
        if (result != null) {
            int curnum = 0;
            int applynum = 0;
            List<StudentInnovationResult> innovationStudentList = innovationStudentGxMapper.getInnovationStudentListById(innovationid);
            for (int i = 0; i < innovationStudentList.size(); i++) {
                if ("1002".equals(innovationStudentList.get(i).getApplystatus())) {
                    curnum++;
                }
                if ("1001".equals(innovationStudentList.get(i).getApplystatus())) {
                    applynum++;
                }
            }
            result.setCurnums(curnum);
            result.setApplynums(applynum);
            result.setStudentInnovationResults(innovationStudentList);
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("老师端根据创新实验id获取单个创新实验下的信息成功！");
            return result;
        } else {
            result.setResult(WebRestResult.FAILURE);
            result.setMessage("老师端根据创新实验id获取单个创新实验下的信息为空！");
            return result;
        }
    }

    @Override
    public PageResult<InnovationStudentPageResult> getStudentListByIdAndStatus(String teacherid, String innovationid, String applystatus, int page, int pagesize) {
        PageResult<InnovationStudentPageResult> result = new PageResult<>();
        int begin = (page - 1) * pagesize;
        int end = pagesize;
        List<InnovationStudentPageResult> list = innovationMapper.getStudentListByIdAndStatus(teacherid, innovationid, applystatus, begin, end, pagesize);
        if (list.size() > 0) {
            result.setRows(list);
            result.setTotal(list.get(0).getCnt());
            result.setPageCount(list.get(0).getPage());
            result.setMessage("老师根据id得到创新实验下申请的学生的列表成功");
            result.setResult(WebRestResult.SUCCESS);
        } else {
            result.setMessage("老师根据id得到创新实验下申请的学生的列表为空");
            result.setResult(WebRestResult.FAILURE);
        }
        return result;
    }

    @Override
    public PageResult<InnovationAdminPageResult> getInnovationListByStudentWeb(String innovationname, String studentid, String applystatus, int page, int pagesize) {
        PageResult<InnovationAdminPageResult> result = new PageResult<>();
        int begin = (page - 1) * pagesize;
        int end = pagesize;

        List<InnovationAdminPageResult> innovationResultList = innovationMapper.getInnovationListByStudentWeb(innovationname, studentid, applystatus, begin, end, pagesize);
        if (innovationResultList.size() > 0) {
            for (InnovationAdminPageResult innovationAdminPageResult : innovationResultList) {
                int curnum = 0;
                int applynum = 0;
                List<StudentInnovationResult> innovationStudentList = innovationStudentGxMapper.getInnovationStudentListById(innovationAdminPageResult.getInnovationid());
                for (int i = 0; i < innovationStudentList.size(); i++) {
                    if ("1002".equals(innovationStudentList.get(i).getApplystatus())) {
                        curnum++;
                    }
                    if ("1001".equals(innovationStudentList.get(i).getApplystatus())||"1003".equals(innovationStudentList.get(i).getApplystatus())) {
                        applynum++;
                    }
                }
                applynum+=curnum;
                innovationAdminPageResult.setCurnums(curnum);
                innovationAdminPageResult.setApplynums(applynum);
//                innovationAdminPageResult.setStudentInnovationResults(innovationStudentList);
            }
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("Web端学生获取创新实验列表成功！");
            result.setRows(innovationResultList);
            result.setTotal(innovationResultList.get(0).getCnt());
            result.setPageCount(innovationResultList.get(0).getPage());
            return result;
        } else {
            result.setResult(WebRestResult.FAILURE);
            result.setMessage("学生没有创新实验列表！");
            return result;
        }
    }

    @Override
    public PageResult<InnovationStudentPageResult> getStudentListByTeacherWeb(String innovationname, String teacherid, String applystatus, int page, int pagesize) {
        PageResult<InnovationStudentPageResult> result = new PageResult<>();
        int begin = (page - 1) * pagesize;
        int end = pagesize;

        List<InnovationStudentPageResult> list = innovationMapper.getStudentListByTeacherWeb(innovationname, teacherid, applystatus, begin, end, pagesize);
        if (list.size() > 0) {
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("老师获取申请了他创新实验的所有学生信息成功！");
            result.setTotal(list.get(0).getCnt());
            result.setPageCount(list.get(0).getPage());
            result.setRows(list);
        }
        return result;
    }

    @Override
    public WebRestResult uploadProjectfileByStudent(String innovationid, String studentid, String projectfile) {
        WebRestResult result = new WebRestResult();
        if (innovationStudentGxMapper.uploadProjectfileByStudent(innovationid, studentid, projectfile,"此接口不使用") == 1) {
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("学生上传创新项目文件成功！");
        }
        return result;
    }

    @Override
    public PageResult<InnovationUserFilePageResult> getProjectfileList(String innovationid, int page, int pagesize) {
        PageResult<InnovationUserFilePageResult> result = new PageResult<>();
        int begin = (page - 1) * pagesize;
        int end = pagesize;

        List<InnovationUserFilePageResult> list = innovationMapper.getProjectfileList(innovationid,begin, end, pagesize);
        if (list.size() > 0) {
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("根据创新实验id得到学生申请的项目文件列表成功！");
            result.setTotal(list.get(0).getCnt());
            result.setPageCount(list.get(0).getPage());
            result.setRows(list);
        }
        return result;
    }

    @Override
    public WebRestResult deleteProjectfile(String innovationid, String userid, String projectfilepath) {
        WebRestResult result = new WebRestResult();
        if (innovationMapper.deleteProjectfile(innovationid, userid, projectfilepath) == 1) {
            result.setResult(WebRestResult.SUCCESS);
            result.setMessage("删除该学生提交的单个创新实验项目文件成功！");
        }
        return result;
    }

    @Override
    public PageResult<InnovationRemindResult> getInnovationRemindByTeacher(String teacherid) {
        PageResult<InnovationRemindResult> result = new PageResult<>();
        List<InnovationRemindResult> list = innovationMapper.getInnovationRemindByTeacher(teacherid, 0, 10000, 10000);
        if (list.size() > 0) {
            result.setMessage("获取提醒成功！");
            result.setTotal(list.get(0).getCnt());
            result.setRows(list);
            result.setPageCount(list.get(0).getPage());
        }
        return result;
    }

}
